<%-- 
    Document   : display_posts
    Created on : 31 May, 2012, 4:34:58 PM
    Author     : bharat
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page  import="java.sql.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ONLINE COLLEGE MAGAZINE</title>
     
    </head>
    <body>
        <%

            String usrname = (String) session.getAttribute("usr");
            out.println(usrname);

            Connection con2 = null;
            PreparedStatement pstmt1 = null;
            ResultSet rs1 = null;

            try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
                con2 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "aksh", "aksh");

                pstmt1 = con2.prepareStatement("select *from posts where postedby=?");
                pstmt1.setString(1, usrname);
                rs1 = pstmt1.executeQuery();
        %>

        <table>
            <tr class="tab">
                <td>Type</td>
                <td>Subject</td>
                <td>Posted on</td>
                <td>Options</td>
            </tr>

            <%
                while (rs1.next()) {
                    //String pid=rs1.getString(1);
%>

            <tr>
                <td><%=rs1.getString(2)%></td>
                <td><a href=".acc_po?pid=<%=rs1.getString(1)%>" target="_top"><%=rs1.getString(3)%></a></td>
                <td><%=rs1.getString(5)%></td>
                <td><a href="delete_post.jsp?pid=<%=rs1.getString(1)%>"> <img src="./images/del.jpg"> </a>
                <a href="edit_post.jsp?pid=<%=rs1.getString(1)%>"> <img src="./images/icon_edit.gif"> </a></td>
            </tr>
            <%                    }
            %>
        </table>
        <%

            } catch (Exception e) {
                response.sendError(503, e.getMessage());
            }finally{
                if(rs1!=null){
                    try{
                        rs1.close();
                    }catch(Exception e){
                        response.sendError(555,e.getMessage());
                    }
                }
                if(pstmt1!=null){
                    try{
                        pstmt1.close();
                    }catch(Exception e){
                        response.sendError(555,e.getMessage());
                    }
                }
                if(con2!=null){
                    try{
                        con2.close();
                    }catch(Exception e){
                        response.sendError(555,e.getMessage());
                    }
                }
            }

        %>
    </body>
</html>
